@{block #content}
<div class="celebriomailapp_settingscontents">
    <h1>{if isset($accountaddress_to_edit)}{_"%s settings",$accountaddress_to_edit}{else}{!_'Mail Server Settings'}{/if}</h1>

    <script type="text/javascript">
	function callSettingsFormPart1() {
	    if(!nette.validateForm(document.getElementById("frmsettingsFormPart1-submited"))) return false;
	    $.ajax({
		url: $("#frm-settingsFormPart1").attr("action"),
		dataType: 'json',
		data: getArrayFromForm("frm-settingsFormPart1"),
		type: "post",
		success: function (payload) {
		    $("#celebriomailapp_settings_snippet").html(payload.snippets["snippet--settingsSnippet"]);
		}
	    });
	    $("#celebriomailapp_settings_snippet").html("");
	    return false;
	}
	function callSettingsForm() {
	    if(!nette.validateForm(document.getElementById("frmsettingsForm-submited"))) return false;
	    $.ajax({
		url: $("#frm-settingsForm").attr("action"),
		dataType: 'json',
		data: getArrayFromForm("frm-settingsForm"),
		type: "post",
		success: function (payload) {
		    $("#celebriomailapp_settings_snippet").html(payload.snippets["snippet--settingsSnippet"]);
		}
	    });
	    $("#celebriomailapp_settings_snippet").html("");
	    return false;
	}
	function checkMailProvider() {
	    mailAddress = $("#frmsettingsFormPart1-mailaddress").val();
	    if(mailAddress == null) return;
	    provider = mailAddress.substr(mailAddress.indexOf("@")+1).toLowerCase();
	    switch(provider){
		case "seznam.cz":
		    $(".celebriomailapp_compatibility_img").html('<img src="{!$basePath}/systemApps/celebriomail/images/providers/emailseznamcz.gif" alt="Email Seznam.cz" />');
		    $(".celebriomailapp_compatibility").css("visibility","visible");
		    break;
		case "gmail.com":
		    $(".celebriomailapp_compatibility_img").html('<img src="{!$basePath}/systemApps/celebriomail/images/providers/gmail.png" alt="Gmail" />');
		    $(".celebriomailapp_compatibility").css("visibility","visible");
		    break;
		case "hotmail.com":
		case "hotmail.cz":
		case "hotmail.co.uk":
		    $(".celebriomailapp_compatibility_img").html('<img src="{!$basePath}/systemApps/celebriomail/images/providers/hotmail.png" alt="Hotmail" />');
		    $(".celebriomailapp_compatibility").css("visibility","visible");
		    break;
		default:
		    $(".celebriomailapp_compatibility").css("visibility","hidden");
	    }
	}
    </script>

    <div id="celebriomailapp_settings_snippet">
	{snippet settingsSnippet}
	    {if isset($_GET["edit"])}<a href="{link Settings:remove,'confirm'=>$account_to_edit}" onclick="return celebriomailappLink({link Settings:remove,'confirm'=>$account_to_edit});" title='{_"Remove %s from Celebrio",$accountaddress_to_edit}'><button>{_"Remove %s from Celebrio",$accountaddress_to_edit}</button></a>{/if}
	    {if isset($settings_status)}<div class="celebriomailapp_status">{$settings_status}</div>{/if}
	    {$settingsForm}
	    <p>{!_"Important: some of the e-mail providers (such as Gmail) require you to allow POP3 or IMAP feature first."}</p>
	    <div class="celebriomailapp_compatibility"><span class="celebriomailapp_compatibility_img">&nbsp;</span>{!_"Celebrio compatible"}</div>
	    {if isset($activeMailServersList)}
	    <div class="celebriomailapp_activeaccounts">
		<h2>{!_"Active E-mail Accounts"}</h2>
		<ul>
		    {foreach $activeMailServersList as $mail}
		    <li><a href="{link Settings:settings,'edit'=>$mail['id']}" onclick="return celebriomailappLink({link Settings:settings,'edit'=>$mail['id']});" title="{!_'Edit %s e-mail account.',$mail['address']}">{$mail["address"]}</a></li>
		    {/foreach}
		</ul>
	    </div>
	    {/if}
	    <script type="text/javascript">
		$(document).ready(function(){
		    if($("#frmsettingsFormPart1-mailaddress").val() != null){
			checkMailProvider();
		    }
		    $("#frmsettingsFormPart1-mailaddress").keyup(function(){
			checkMailProvider()
		    });
		    $("#frmsettingsFormPart1-mailaddress").change(function(){
			checkMailProvider()
		    });
		    $("#frmsettingsFormPart1-submited").click(function(event){
		       event.preventDefault();
		       callSettingsFormPart1();
		    });
		    $("#frmsettingsForm-submited").click(function(event){
		       event.preventDefault();
		       callSettingsForm();
		    });
		});
	    </script>
	{/snippet}
    </div>
</div>
{/block}